/************************************************/
/************************************************/
/*** PART 4.3: APPENDIX TABLE 2 ***/
/************************************************/
/************************************************/

	preserve

	keep if sample1==1
	
	collapse braven baseline_tterm refshare refugee maleshare csize bturk_std bmath_std b_schoolid b_classid urfa biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried ttenured bteyes bteyes_sd btraven btraven_sd b_pedagogy b_gms b_modern b_extrinsic b_warmth b_idealism b_competence grade1 dist1-dist10 bcoleman_ref1_friend bcoleman_ref1_supportself bcoleman_ref1_studyself baseline_tchildnum bcoleman_ref2_friend bcoleman_ref2_supportself bcoleman_ref2_studyself b_districtid ref_s_exposure bexper btsurvey_16_refprop , by(btname)


******************************************************
*** REFUGEE DISTRIBUTION OVER CLASSROOMS ***
*** (SELECTION CHECK) ***
*******************************************************

	** school, province and classroom effect on refshare in a classroom (selection)
	
	reg refshare biat_ethnic csize i.grade1 i.b_schoolid urfa, cluster(b_classid)
	estimates store spec1
	scalar i1=e(r2)
	test biat_ethnic=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec1
	estadd scalar pr2=i1 : spec1

	** How much additional variation is explained by bias+teacher demographics
	
	reg refshare biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btsurvey_16_refprop csize i.grade1 i.b_schoolid urfa, cluster(b_classid)
	estimates store spec2
	scalar i1=e(r2)
	test biat_ethnic=baseline_tmale=baseline_tage=baseline_texperience=tmarried=baseline_tchildnum=ttenured=btsurvey_16_refprop=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec2
	estadd scalar pr2=i1 : spec2

	** How much additional variation is explained by teacher bias+demographics+cognition
	
	reg refshare biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btsurvey_16_refprop btraven_sd bteyes_sd csize i.grade1 i.b_schoolid urfa, cluster(b_classid)
	estimates store spec3
	scalar i1=e(r2)

	test biat_ethnic=baseline_tmale=baseline_tage=baseline_texperience=tmarried=baseline_tchildnum=ttenured=btsurvey_16_refprop=btraven_sd=bteyes_sd=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec3
	estadd scalar pr2=i1 : spec3

	** How much additional variation is explained by teacher bias+demographics+cognition+styles
	
	reg refshare biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btsurvey_16_refprop btraven_sd bteyes_sd b_gms b_pedagogy b_modern b_extrinsic b_warmth b_competence b_idealism  csize i.grade1 i.b_schoolid urfa, cluster(b_classid)
	estimates store spec4
	scalar i1=e(r2)

	test biat_ethnic=baseline_tmale=baseline_tage=baseline_texperience=tmarried=baseline_tchildnum=ttenured=btsurvey_16_refprop=btraven_sd=bteyes_sd=b_gms=b_pedagogy=b_modern=b_extrinsic=b_warmth=b_competence=b_idealism=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec4
	estadd scalar pr2=i1 : spec4

	#delimit ;
	esttab spec1 spec2 spec3 spec4  using "$path2/appendix_tableA2.tex",  replace label compress b(%8.2f) se(2) noconstant
	nonumbers keep(biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btraven_sd bteyes_sd b_gms b_pedagogy b_modern b_extrinsic b_warmth  b_competence b_idealism btsurvey_16_refprop)
	coeflabels(biat_ethnic "Teacher Ethnic Bias" baseline_tmale "\addlinespace[1mm] Male Teacher" tmarried "Married Teacher" ttenured "Tenured Teacher" baseline_tage "Teacher Age" baseline_texperience "Years of Experience" baseline_tchildnum "Number of Children" bteyes_sd "Teacher Cognitive Empathy Score" btraven_sd "\addlinespace[1mm] Teacher Raven Score" b_gms "\addlinespace[1mm] Growth Mindset" b_pedagogy "Inquiry-based Pedagogy" b_modern "Modern Teaching" b_extrinsic "Extrinsic Motivation" b_warmth "Warmth" b_competence "\addlinespace[1mm] Competence" b_idealism "Professional Satisfaction" csize "Class Size" btsurvey_16_refprop "Desired Work Province - \% of refugee")
	star(* 0.10 ** 0.05 *** 0.01) nonotes 
	s(N pr1 pr2, fmt(%9.0g %9.3f %9.3f) labels("N" "P-Value of Joint Significance" "R-Squared"))
	nogaps
	mtitles ( "(1)" "(2)" "(3)" "(4)")
	refcat(baseline_tmale "\textbf{Teacher Demographics:}" b_gms "\addlinespace[1.5mm] \textbf{Teaching Styles:}"  btraven_sd "\addlinespace[1.5mm] \textbf{Teacher Cognition:}" b_competence "\textbf{Teacher Motivation:}", nolabel)
	;
	#delimit cr

	restore
